﻿using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;

namespace WDA.Core
{
   /// <summary>
   /// Configurator implementation for Unity configuration section.
   /// </summary>
   public sealed class UnityConfigModuleConfigurator : IModuleConfigurator
   {
      private readonly UnityContainerElement _configElement;
      private readonly string _targetModule;

      /// <summary>
      /// Creates new configurator instance.
      /// </summary>
      /// <param name="targetModule">Name of target module's container.</param>
      /// <param name="configElement">Configuration settings.</param>
      public UnityConfigModuleConfigurator(string targetModule, UnityContainerElement configElement)
      {
         _targetModule = targetModule;
         _configElement = configElement;
      }

      #region IModuleConfigurator Members
      public bool ShouldApply(string moduleContainerName)
      {
         return _targetModule == moduleContainerName;
      }
      public void Apply(IUnityContainer moduleContainer)
      {
         _configElement.Configure(moduleContainer);
      }
      #endregion
   }
}
